<template>
  <div class="TotalMoney overflowY">
    <!--<div class="PageTitle"><i class="iconfont icon-jia"></i>费用结算</div>-->
    <div class="PageContent">

      <el-form :model="chargeData" :inline="true" ref="ruleForm" label-width="120px" class="demo-ruleForm"
               @submit.native.prevent>
        <div class="PageItem margintop20">
          <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0> 
            <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0></embed>
          </object>
          <el-row :gutter="0" class="paddingleft2">
            <el-form-item label="业务编码:" prop="name">
              <el-input v-model="businessCode" ref="totalbusinessCode" @keyup.enter.native="searchData(businessCode)"
                        :maxlength="20" placeholder="请输入业务编码"
                        style="width:230px" @snedmsg="determine($even)">
                <el-button
                  type="primary"
                  slot="append"
                  icon="el-icon-circle-close"

                  @click="businessCode=''"
                ></el-button>
                <el-button type="primary" slot="append" icon="el-icon-search" v-if="btnRight.btnTotalMoneyCodeScanning"
                           @click="searchData(businessCode)"></el-button>
              </el-input>
            </el-form-item>

            <el-button type="primary"    v-if="btnRight.btnBusinessSearch"  @click="businessSearchShow()">业务查询</el-button>
            <!--<el-button type="primary" style="margin-left:20px;" @click="searchData(businessCode)">扫描</el-button>-->
            <el-form-item label="业务编码:">
                <span class="cont">{{ chargeData.funeralDead.businessCode }}</span>
            </el-form-item>
            <el-form-item label="逝者姓名:">
              <span class="titlecont">{{ chargeData.funeralDead.deadName }}</span>
            </el-form-item>
            <!-- <el-form-item label="减免区域:">
              <span class="titlecont">{{ chargeData.funeralDead.benefitDistrict }}</span>
            </el-form-item> -->
            <el-form-item label="减免类型:">
              <span class="titlecont">{{ chargeData.funeralDead.exemptionType }}</span>
            </el-form-item>
            <el-form-item label="家属姓名:">
              <span class="titlecont">{{ chargeData.familyMember.memberName }}</span>
            </el-form-item>
            <i class="el-icon-arrow-down more" v-if="!moreFlag" @click="moreFlag=!moreFlag">&nbsp;展开</i>
            <i class="el-icon-arrow-up more" v-if="moreFlag" @click="moreFlag=!moreFlag">&nbsp;收起</i>
          </el-row>
        </div>
        <div class="PageItem " v-if="moreFlag">
          <div style="display: inline-block;">
            <el-row class="PageInfo"><i class="el-icon-location"></i>逝者基本信息</el-row>
            <el-row :gutter="0" class="paddingleft2">
              <el-form-item label="业务编码:">
                <span class="cont">{{ chargeData.funeralDead.businessCode }}</span>
              </el-form-item>
              <el-form-item label="逝者姓名:">
                <span class="cont">{{ chargeData.funeralDead.deadName }}</span>
              </el-form-item>
              <el-form-item label="证件号码:">
                <span class="cont">{{ chargeData.funeralDead.certificateNo }}</span>
              </el-form-item>
              <el-form-item label="性别:">
                <span class="cont">{{ chargeData.funeralDead.deadGender }}</span>
              </el-form-item>
            </el-row>
            <el-row :gutter="0" class="paddingleft2">
              <el-form-item label="减免区域:">
                <span class="cont">{{ chargeData.funeralDead.benefitDistrict }}</span>
              </el-form-item>
              <el-form-item label="减免类型:">
                <span class="cont">{{ chargeData.funeralDead.exemptionType }}</span>
              </el-form-item>
              <el-form-item label="接尸地点:">
                <span class="cont">{{ chargeData.funeralDead.transportPlace }}</span>
              </el-form-item>
              <el-form-item label="火化证号:">
                <span class="cont">{{ chargeData.funeralDead.cremationNo }}</span>
              </el-form-item>
              <el-form-item label="死亡原因:">
                <span class="cont">{{ chargeData.funeralDead.deathCause }}</span>
              </el-form-item>
            </el-row>
            <el-row class="PageInfo"><i class="el-icon-location"></i>家属基本信息</el-row>
            <el-row :gutter="0" class="paddingleft2">
              <el-form-item label="家属姓名:">
                <span class="cont">{{ chargeData.familyMember.memberName }}</span>
              </el-form-item>
              <el-form-item label="证件号码:">
                <span class="cont">{{ chargeData.familyMember.certificateNo }}</span>
              </el-form-item>
              <el-form-item label="与逝者关系:">
                <span class="cont">{{ chargeData.familyMember.memberRelation }}</span>
              </el-form-item>
              <el-form-item label="联系方式:">
                <span class="cont">{{ chargeData.familyMember.mobilePhone }}</span>
              </el-form-item>
            </el-row>
            <el-row class="PageInfo"><i class="el-icon-location"></i>承办人基本信息</el-row>
            <el-row :gutter="0" class="paddingleft2">
              <el-form-item label="承办人姓名:">
                <span class="cont"
                      v-if="chargeData.familyAgent.agentType==1 && chargeData.familyAgent.agentUnitName">{{
                    chargeData.familyAgent.agentUnitName
                  }}</span>
                <span class="cont" v-else-if="chargeData.familyAgent.agentType==0 && chargeData.familyAgent.agentName">{{
                    chargeData.familyAgent.agentName
                  }}</span>
                <span class="cont" v-else>{{ chargeData.familyAgent.agentName }}</span>
              </el-form-item>
              <el-form-item label="证件号码:">
                <span class="cont">{{ chargeData.familyAgent.certificateNo }}</span>
              </el-form-item>
              <el-form-item label="与逝者关系:">
                <span class="cont">{{ chargeData.familyAgent.agentRelation }}</span>
              </el-form-item>
              <el-form-item label="联系方式:">
                <span class="cont">{{ chargeData.familyAgent.mobilePhone }}</span>
              </el-form-item>
            </el-row>
          </div>

        </div>
        <el-row></el-row>
        <div class="PageItem marginbottom0">
          <el-row class="PageInfo">
            <i class="el-icon-location"></i>费用信息
          </el-row>
          <div class="border1">
            <el-table
              :data="chargeData.chargeItems"
              :header-cell-style="{background:'rgb(246,247,251)',color:'#606266'}"
              stripe
              style="width: 100%;"
              @selection-change="handleSelectionChange">
              <el-table-column
                type="selection"
                :selectable="selectable"
                width="50">
              </el-table-column>
              <el-table-column
                prop="itemName"
                align='center'
                label="服务、物品(单击名称可修改)"
                width="200">
                <template slot-scope="{row,$index}">
                  <span @click="editTable($index,row)">{{ row.itemName }}</span>
                </template>
              </el-table-column>
              <el-table-column prop="itemPrice" align='right' label="单价" width="120">
              </el-table-column>
              <el-table-column prop="itemNumber" align='right' label="数量" width="100">
              </el-table-column>
              <el-table-column prop="itemCharge" align='right' label="总金额" width="100">
              </el-table-column>
              <el-table-column prop="discountCharge" align='right' label="优惠" width="120">
              </el-table-column>
              <el-table-column prop="benefitCharge" align='right' label="减免" width="120">
              </el-table-column>
              <el-table-column prop="realityCharge" align='right' label="实收" width="120">
              </el-table-column>
              <el-table-column prop="asSettled" align='center' label="结算状态" width="120">
                <template slot-scope="{row,$index}">
                  <span v-if="row.asUnsettled==1" style="color: #f00;">不可结算</span>
                  <span v-else-if="row.asSettled==0">未结算</span>
                  <span v-else-if="row.asSettled==1">已结算</span>
                </template>
              </el-table-column>
              <el-table-column prop="settleBatchNo" align='center' label="结算批次编号" min-width="200px">
              </el-table-column>
              <el-table-column prop="settleTime" align='center' label="结算时间" width="120">
              </el-table-column>
              <el-table-column prop="payType" align='center' label="付款方式" width="120">
              </el-table-column>
              <el-table-column prop="asVerify" align='center' label="操作" width="100">
                <template slot-scope="{row,$index}">
                  <span
                    v-if="row.asSettled==0 ||  row.realityCharge<=0  || row.asBusiness==1 || row.asRefund==1 "></span>
                  <span v-else-if="row.asSettled==1" @click="openRefund(row)">退费</span>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <hr style="margin-top:50px;">
          <div class="font16" style="text-align:right;">
            <div style="display: inline-block;height: 80px;line-height: 80px;vertical-align: bottom;">
              总费用合计:<span class="totalw">{{ Charge.total }}</span>元
            </div>
            <div style="padding-left:30px;display: inline-block;">
              <div style="line-height: 40px;">
                已结算:<span class="totalw">{{ Charge.Settled }}</span>元， 优惠:
                <span class="totalw">{{ Charge.discountCharge }}</span>元， 减免:
                <span class="totalw">{{ Charge.benefitCharge }}</span>元， 实收合计:
                <span class="totalw">{{ Charge.realityCharge }}</span>元
              </div>
              <div style="line-height: 40px;">
                未结算:<span class="totalw">{{ Charge.unSettled }}</span>元， 优惠:
                <span class="totalw">{{ Charge.unDiscountCharge }}</span>元， 减免:
                <span class="totalw">{{ Charge.unBenefitCharge }}</span>元， 待付金额:
                <span class="totalw">{{ Charge.unrealityCharge }}</span>元
              </div>
            </div>
          </div>
          <el-row :gutter="30" style="text-align: right;margin:30px 0; ">
            <el-button type="primary"  plain @click="loadBoneAshByBusinessCode">
              <!-- <el-button type="primary" v-if="btnRight.btnBusinessCodeBoneAsh" plain @click="loadBoneAshByBusinessCode"> -->
              打印骨灰盒二维码
            </el-button>
            <el-button type="primary" v-if="btnRight.btnTotalMoneyPrintChargeItem" plain
                       @click="loadChargeDetailWithId">打印收费明细
            </el-button>
            <el-button type="primary" v-if="btnRight.btnPrintQuHuiZhengMing" plain @click="loadDeadInfoByBusinessCode">
              打印取灰证明
            </el-button>
            <el-button type="primary" v-if="btnRight.btnPrintAbatementList" plain @click="PrintAbatementList">
              打印减免基本殡葬服务费用申请表
            </el-button>
            <!-- v-if="btnRight.btnPrintQuHuiZhengMing" -->
            <el-button type="primary" v-if="btnRight.btnTotalMoneyExpenseSettlement" @click="NowPay">费用结算</el-button>
          </el-row>
        </div>
        <div class="PageItem ">
          <el-row class="PageInfo">
            <i class="el-icon-add-location"></i>结算历史记录
          </el-row>
          <div class="border1">
            <el-table :data="chargeData.chargeSettles" border
                      :header-cell-style="{background:'rgb(246,247,251)',color:'#606266'}" stripe style="width: 100%;"
                      @selection-change="handleSelectionChangeHistory">
              <el-table-column type="selection" width="50">
              </el-table-column>
              <el-table-column align='center' prop="settleTime" label="结算时间" width="200">
              </el-table-column>
              <el-table-column prop="settleCharge" align='right' label="结算金额" width="100">
              </el-table-column>
              <el-table-column prop="settleType" align='center' label="结算方式" width="120">
              </el-table-column>
              <el-table-column prop="receiptNo" align='center' label="收据号" min-width="200px">
              </el-table-column>
              <el-table-column prop="settleBatchNo" align='center' label="结算批次编号" width="200">
              </el-table-column>
              <el-table-column prop="settleUserName" align='center' label="经办人" width="100">
              </el-table-column>
              <el-table-column prop="payType" align='center' label="付款方式" width="120">
              </el-table-column>
              <el-table-column prop="asVerify" align='center' label="日结审核" width="100">
                <template slot-scope="{row,$index}">
                  <span v-if="row.asVerify==0">未审核</span>
                  <span v-else-if="row.asVerify==1">已审核</span>
                </template>
              </el-table-column>
              <el-table-column label="操作" align='center'>
                <template slot-scope="{row,$index}">
                  <div v-if="row.asVerify==0 && row.settleCharge>0 && row.asInvoice==0 && row.asRefund==0">
                    <el-button
                      size="small"
                      type="text"
                      @click.native.prevent="cancellation($index, row)">撤销结算
                    </el-button>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <el-row :gutter="30" style="text-align: right;margin:30px 0; ">
            <el-button type="primary" v-if="btnRight.btnTotalMoneyPrintHistoryItem" plain
                       @click.native.prevent="loadChargeSettleDetailWithId">
              打印收费明细
            </el-button>
            <el-button type="primary" v-if="btnRight.btnTotalMoneyPrintInvoice" plain
                       @click.native.prevent="printInvoice">
              打印发票
            </el-button>
            <el-button type="primary" v-if="btnRight.btnTotalMoneyPrintInvoice" @click.native.prevent="InvoiceManager">
              发票管理
            </el-button>
          </el-row>
        </div>

      </el-form>
    </div>
    <el-dialog title="服务、物品详情" :visible.sync="dialogFormVisible" center width="30%">
      <el-form :model="chargeitemwithid" ref="dialogForm" label-width="100px" class="demo-ruleForm"
               :disabled="chargeSaveFlag">
        <el-form-item label="名称">
          <el-input v-model="chargeitemwithid.itemName" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="单价">
          <el-input type="number" v-model="chargeitemwithid.itemPrice" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="数量">
          <el-input type="number" v-model="chargeitemwithid.itemNumber" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="单位">
          <el-input v-model="chargeitemwithid.itemUnit" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="项目金额">
          <el-input type="number" v-model="chargeitemwithid.itemCharge" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="优惠金额">
          <el-input type="number" v-model="chargeitemwithid.discountCharge"
                    :disabled="chargeitemwithid.asSettled==0?false:true"></el-input>
        </el-form-item>
        <el-form-item label="减免金额">
          <el-input type="number" v-model="chargeitemwithid.benefitCharge"
                    :disabled="chargeitemwithid.asSettled==0?false:true"></el-input>
        </el-form-item>
        <el-form-item label="实际收费">
          <el-input type="number" v-model="chargeitemwithid.realityCharge" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="结算状态">
          <el-input v-if="chargeitemwithid.asSettled==0" v-model="chargeitemwithid.asSettled" :disabled="true">否
          </el-input>
          <el-input v-if="chargeitemwithid.asSettled==1" v-model="chargeitemwithid.asSettled" :disabled="true">是
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="savecharge">保存</el-button>
      </div>
    </el-dialog>
    <el-dialog title="发票及收据修改" :visible.sync="dialogchangeVisible" center width="30%">
      <el-form :model="changeinvoice" ref="dialogchange" label-width="100px" class="demo-ruleForm"
               :disabled="changeinvoicesaveFlag">
        <el-form-item label="结算时间">
          <el-input v-model="changeinvoice.settleTime" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="结算金额">
          <el-input v-model="changeinvoice.settleCharge" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="付款方式">
          <el-input v-model="changeinvoice.settleType" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="发票号">
          <el-input v-model="changeinvoice.invoiceNo" :maxlength="20"></el-input>
        </el-form-item>
        <el-form-item label="发票代码">
          <el-input v-model="changeinvoice.invoiceCode" :maxlength="20"></el-input>
        </el-form-item>
        <el-form-item label="收据号">
          <el-input v-model="changeinvoice.receiptNo" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="发票抬头">
          <el-input v-model="changeinvoice.invoiceTitle" :maxlength="20"></el-input>
        </el-form-item>
        <el-form-item label="经办人">
          <el-input v-model="changeinvoice.settleUserName" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="changeinvoice.remark"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogchangeVisible = false">取 消</el-button>
        <el-button type="primary" @click="savechargesettlechangeinvoice(changeinvoice.id)">保存</el-button>
      </div>
    </el-dialog>
    <NowPayDialog :NowPayFlag="NowPayFlag" :btnRight="btnRight" :businessCode="businessCode"
                  :multipleSelection="multipleSelection" :totalCharge="totalCharge"></NowPayDialog>
    <RefundDialog :RefundDialogFlag="RefundDialogFlag" :businessCode="businessCode" :RowSelection="refundSelection"
                  :totalCharge="totalCharge"></RefundDialog>
    <InvoiceDialog :InvoiceDialogFlag="InvoiceDialogFlag" :businessCode="businessCode"
                   :totalCharge="totalCharge"></InvoiceDialog>
    <PrintInvoiceDialog :PrintInvoiceFlag="PrintInvoiceFlag" :multipleSelectionHistory="multipleSelectionHistory"
                        :businessCode="businessCode"></PrintInvoiceDialog>
    <SearchDialog :DialogSearch="DialogSearch" :copyCremationTypes="dictionary.cremation_type"></SearchDialog>

  </div>
</template>

<script>
import * as Type from "@/api/service";
import NowPayDialog from "../dialog/NowPayDialog";
import RefundDialog from "../dialog/RefundDialog";
import { toFixed } from "@/utils/tofixed";
import { getLodop } from "@/utils/lodopFuncs";
import { dataFormate } from "@/utils/index";
import InvoiceDialog from "../dialog/InvoiceDialog";
import PrintInvoiceDialog from "../dialog/PrintInvoiceDialog";
import SearchDialog from '../dialog/SearchDialog'

export default {
  name: "TotalMoney",
  components: {
    PrintInvoiceDialog,
    InvoiceDialog,
    NowPayDialog,
    RefundDialog,
    SearchDialog,
  },
  data() {
    return {
      DialogSearch: false, //业务查询
      RefundDialogFlag: false, //退费对话框打开标志
      InvoiceDialogFlag: false, //发票管理对话框打开标志
      PrintInvoiceFlag: false, //打印发票
      refundSelection: {}, //选中要退费的信息
      businessCode: "",
      moreFlag: false, //折叠
      chargeData: {
        funeralDead: {
          id: 0,
          businessCode: "",
          deadName: "",
          certificateNo: "",
          deadGender: "",
          benefitDistrict: "",
          exemptionType: "",
          transportPlace: "",
          cremationNo: "",
          version: 0,
        },
        familyMember: {
          id: 0,
          memberName: "",
          certificateNo: "",
          memberRelation: "",
          mobilePhone: "",
          otherPhone: "",
          version: 0,
        },
        familyAgent: {
          id: 0,
          agentType: 0,
          agentUnitName: "",
          agentName: "",
          mobilePhone: "",
          otherPhone: "",
          certificateNo: "",
          agentRelation: "",
          version: 0,
        },
        chargeItems: [],
        chargeSettles: [],
        abatementTotalCharge: 0,
        abatementTotalChargeText: "",
      },
      chargeitemwithid: {
        id: 0,
        businessCode: "string",
        serviceItemId: 0,
        itemName: "string",
        itemPrice: 0,
        itemNumber: 0,
        itemUnit: "string",
        itemCharge: 0,
        discountCharge: 0, //优惠金额
        benefitCharge: 0, //减免金额
        realityCharge: 0,
        chargeTime: "string",
        asSettled: 0,
        randomCode: "string",
        version: 0,
      },
      chargeSaveFlag: false, //保存过程中不可更改,true为正在保存
      changeinvoice: {
        id: 0,
        settleTime: "",
        settleCharge: 0,
        settleType: "",
        invoiceCode: "",
        invoiceNo: "",
        receiptNo: "",
        settleBatchNo: "",
        settleUserName: "",
        asVerify: 0,
        remark: "",
        version: 0,
      },
      changeinvoicesaveFlag: false, //保存过程中不可更改,true为正在保存
      dialogFormVisible: false,
      dialogchangeVisible: false,
      dictionary: {},
      showEdit: [], //显示编辑框
      NowPayFlag: false, //直接付款
      multipleSelection: [],
      multipleSelectionHistory: [], //结算历史选择
      totalCharge: 0, //选择总费用
      btnRight: {
        //按钮权限
        btnTotalMoneyCodeScanning: true, //业务编码扫码按钮
        btnBusinessCodeBoneAsh: true, //打印骨灰盒二维码
        btnTotalMoneyPrintChargeItem: true, //打印收费明细
        btnTotalMoneyExpenseSettlement: true, //费用结算
        btnTotalMoneyPrintHistoryItem: true, //打印收费明细
        btnTotalMoneyPrintInvoice: true, //打印发票
        btnNowPaySave: true, //费用结算保存
        btnNowPayCancel: true, //费用结算取消
        //打印减免表
        btnPrintAbatementList: true,
        //打印取灰证明
        btnPrintQuHuiZhengMing: true,
        btnBusinessSearch: true, //业务查询
      },
    };
  },
  mounted() {
    //按钮权限
    this.btnRight = this.$route.meta.buttons;
    //遍历属性赋值将true与false字符串转换成布尔型的值
    for (let key of Object.keys(this.btnRight)) {
      this.btnRight[key] =
        this.btnRight[key] || this.btnRight[key] == "true" ? true : false;
    }
    this.businessCode = this.$store.getters.businessCode;
    if (this.businessCode != null && this.businessCode != "") {
      this.searchData(this.businessCode);
    }
    //businessCode获得焦点
    this.$refs["totalbusinessCode"].focus();
  },
  methods: {
    determine(event){
      console.log(event,999)
    },
         //业务查询显示
    businessSearchShow() {
      this.DialogSearch = true;
    },
    selectChange() {
      //给业务编码设置焦点
      this.$refs.deathChange_ref.blur();
      this.$refs.servicebusinessCode.focus();
    },
    //打开退费窗口
    openRefund(row) {
      let this_open = this;
      if (row && row.id) {
        let postData = {
          id: row.id,
        };
        Type["loadchargeitemwithid"](postData)
          .then((response) => {
            const { data } = response;
            if (!data) {
              this_open.$message("数据读取失败");
              return;
            }
            //判断是否已退费用   data.asRefund ||data.asRefund==1 ||data.total<=0 || data.refundId != null   退费用asRefund==1的不允许退费
            if (data.asRefund == 1 || data.total <= 0) {
              this_open.$message("费用为负,为零,已退费记录,不允许退费用");
            } else {
              this_open.refundSelection = data;
              //对话框显示
              this_open.RefundDialogFlag = true;
            }
            //查询退费用详细,不是从row获得，而是查数据库得来的数据
          })
          .catch((error) => {
            this_open.$message(error);
          });
      }
    },
    //数据读取
    ReadData() {
      if (!this.businessCode || this.businessCode.length == 0) {
        this.$message("请输入业务编码");
        return;
      }
      let postData = {
        businessCode: this.businessCode,
      };
      Type["loadchargesettlementall"](postData)
        .then((response) => {
          const { data } = response;
          if (!data) {
            this.$message("数据读取失败");
            return;
          }
          this.chargeData = data;
        })
        .catch((error) => {
          this.$message(error);
        });
        //this.businessCode="";
    }, //去掉左右空格
    trim(str) {
      if (str == null) {
        return "";
      }
      return str.replace(/^\s*(.*?)[\s\n]*$/g, "$1");
    }, //查询业务编码
    searchData(code) {
      // code1=$Save.sendMsg;
      // console.log(code1,888888);
      // this.chargeData.funeralDead.businessCode;
      code=this.businessCode;
      if (!code || code.length == 0) {
        this.$message("请输入业务编码");
        return;
      }
      //去掉左右空格
      this.businessCode = this.trim(code);
      this.$store
        .dispatch("user/setbusinessCode", code)
        .catch(() => console.log("promise catch err"));
      this.ReadData();
     //this.businessCode="";
    },
    editTable(index, row) {
      let postData = {
        id: row.id,
      };
      Type["loadchargeitemwithid"](postData)
        .then((response) => {
          const { data } = response;
          if (!data) {
            this.$message("数据读取失败");
            return;
          }
          this.chargeitemwithid = data;
          this.chargeitemwithid.asSettled = row.asSettled;
          // this.dialogFormVisible = true;
        })
        .catch((error) => {
          this.$message(error);
        });
      this.dialogFormVisible = true; //测试用
    },
    savecharge() {
      this.chargeSaveFlag = true;
      let postData = this.chargeitemwithid;

      Type["savechargeitemwithid"](postData)
        .then((response) => {
          const { data } = response;
          if (!data) {
            this.$message("保存读取失败");
            return;
          }
          this.chargeitemwithid = data;
          this.ReadData();
        })
        .catch((error) => {
          this.$message(error);
        });
      this.chargeSaveFlag = false;
    },
    //设置是否选中
    selectable(row, index) {
      if (row.asSettled == 1 || row.asUnsettled == 1) {
        return false;
      } else {
        return true;
      }
    },
    handleSelectionChange(val) {
      let itemArray = [];
      let totalLocal = 0;
      val.forEach((item) => {
        //未结算的
        if (item.asSettled == 0) {
          //计算总金额
          totalLocal += Number(item.itemCharge);
          itemArray.push(item);
        }
      });
      this.multipleSelection = itemArray;
      this.totalCharge = totalLocal;
    },
    handleSelectionChangeHistory(val) {
      this.multipleSelectionHistory = val;
    },
    //点击编辑,作废，发票管理已处理，不需要再用修改来操作发票号
    handleEdit(index, row) {
      if (row.id) {
        Object.assign(this.changeinvoice, row);
        // console.log(this.changeinvoice)
        this.dialogchangeVisible = true;
      } else {
        this.$message("编辑出错");
      }
    },
    savechargesettlechangeinvoice(id) {
      this.changeinvoicesaveFlag = true;
      let postData = {
        id: id,
        businessCode: this.businessCode,
        invoiceCode: this.changeinvoice.invoiceCode,
        invoiceNo: this.changeinvoice.invoiceNo,
        invoiceTitle: this.changeinvoice.invoiceTitle,
        remark: this.changeinvoice.remark,
        version: this.changeinvoice.version,
      };
      Type["savechargesettlechangeinvoice"](postData)
        .then((response) => {
          this.$message("保存成功");
          this.ReadData();
        })
        .catch((error) => {
          this.$message(error);
        });
      this.changeinvoicesaveFlag = false;
      this.dialogchangeVisible = false;
    },
    //撤销结算
    cancellation(index, row) {
      //确认是否撤销结算
      this.$confirm("确认是否撤销结算, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //点击确定的操作(撤销结算)
          let ids = [];
          ids.push({
            id: row.id,
            version: row.version,
          });
          let postData = {
            businessCode: this.businessCode,
            ids: ids,
          };
          Type["savechargesettletocancellationsettlement"](postData)
            .then((response) => {
              if (response) {
                this.$message("执行成功");
              }
              this.ReadData();
            })
            .catch((error) => {
              this.$message(error);
            });
        })
        .catch(() => {});
    }, //载入收费明细信息
    loadChargeDetailWithId() {
      let this_print = this;
      let chargeItems = this.multipleSelection;
      let item = null;
      let chargeArray = [];
      if (chargeItems && chargeItems.length > 0) {
        for (let i = 0; i < chargeItems.length; i++) {
          item = chargeItems[i];
          chargeArray.push({
            id: item.id,
            version: item.version,
          });
        }
      }
      let postData = {
        businessCode: this_print.businessCode,
        ids: chargeArray,
      };

      Type["loadPrintChargeDetailsWithId"](postData)
        .then((response) => {
          //接收返回数据
          let result = response.data;
          //调用打印接口
          this_print.printChargeSettleDetailWithId(result);
        })
        .catch((error) => {
          this_print.$message(error);
        });
    },
    //载入收费明细信息
    loadBoneAshByBusinessCode() {
      let this_print = this;
      let postData = {
        businessCode: this_print.businessCode,
      };
      //打印骨灰盒条码
      Type["loadPrintCremationUrnCodeWithBusinessCode"](postData)
        .then((response) => {
          //接收返回数据
          let result = response.data;
          //调用打印接口
          this_print.printBoneAsh(result);
        })
        .catch((error) => {
          this_print.$message(error);
        });
    },
    //查询逝者信息
    loadDeadInfoByBusinessCode() {
      let this_print = this;
      let postData = {
        businessCode: this_print.businessCode,
      };

      // this_print.printQuHuiZhengMing("");
      //打印取灰证明
      Type["loadPrintCremationAshInfo"](postData)
        .then((response) => {
          //接收返回数据
          let result = response.data;
          //调用打印接口
          this_print.printQuHuiZhengMing(result);
        })
        .catch((error) => {
          this_print.$message(error);
        });
    },
    //打印取灰证明
    printQuHuiZhengMing(printData) {
      let this_print = this;
      let LODOP = getLodop();
      if (LODOP == null || !LODOP) {
        this_print.$.messager.alert(
          "系统提示",
          "您的浏览器不支持打印控件，请用IE重试或安装打印控件后重试"
        );
        return;
      }
      console.log(printData, "quhuizhengming");

      for (let key in printData.funeralDead) {
        printData["cremation"][key] = printData["cremation"][key]
          ? printData["cremation"][key]
          : "　";

        printData["familyAgent"][key] = printData["familyAgent"][key]
          ? printData["familyAgent"][key]
          : "　";

        printData["funeralDead"][key] = printData["funeralDead"][key]
          ? printData["funeralDead"][key]
          : "　";
      }

      let recOperationcode = printData.businessCodeBoneAshTake;
      let table = `  <div>
            <div style="height: 40px"></div>
            <table width="720" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                    <td height="30" align="center" >
                        <h2>骨灰领取证明</h2>
                    </td>
                    <td rowspan="2" width="100"  style="padding-top:80px;"></td>
                </tr>
                <tr align="center">
                    <td>证明编号：${printData.cremation.cremationNo}</td>
                </tr>
            </table>
            <table width="720" border="0" align="center" cellpadding="3" cellspacing="0"
                style="border-collapse: collapse;">
                <tr>
                    <td colspan="2"><span style="width: 150px; height: 30px; border-bottom: 1px solid #666; display: block; float: left; line-height: 40px;">临沂市第二殡仪馆</span>  <span style="float: left; height: 40px; line-height: 40px;">骨灰领取处：</span>
                        <div style="float: left">
                            <span style="float: left; height: 40px; line-height: 40px; padding-left: 60px;">丧事承办人：</span>
                            <span style="width: 180px; height: 30px; border-bottom: 1px solid #666; display: block; float: left; line-height: 40px;">
                              ${printData.familyAgent.agentName}</span>
                            <span style="float: left; height: 40px; line-height: 40px;">（证件号码：</span>
                            <span style="width: 140px; height: 30px; border-bottom: 1px solid #666; display: block; float: left; line-height: 40px;">
                              ${printData.familyAgent.certificateNo}
                            </span>
                            <span style="float: left; height: 40px; line-height: 40px;">），凭此证明领取</span>
                            <span style="width: 100px; height: 30px; border-bottom: 1px solid #666; display: block; float: left; line-height: 40px;">
                              ${printData.funeralDead.deadName}
                            </span>
                            <span style="float: left; height: 40px; line-height: 40px;">（身份证号：</span>
                            <span style="width: 230px; height: 30px; border-bottom: 1px solid #666; display: block; float: left; line-height: 40px;">
                              ${printData.funeralDead.certificateNo}
                            </span>
                            <span style="float: left; height: 40px; line-height: 40px;">）的骨灰和《火化证明》。</span>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td ></td>
                  <td style="width: 240px;">出证明单位（公章）</td>
                </tr>
                <tr>
                  <td >出证明业务员签名：<br /> </td>
                  <td style="width: 240px;"> ${this.date ? this.date : ""}</td>
                </tr>
                <tr>
                  <td >骨灰领取处业务员签名：<br /></td>
                  <td style="width: 240px;">年 &nbsp; &nbsp; &nbsp;  月  &nbsp; &nbsp; &nbsp; 日</td>
                </tr>
                <tr>
                  <td >丧事承办人签名：<br /></td>
                  <td style="width: 240px;" >年  &nbsp; &nbsp; &nbsp; 月  &nbsp; &nbsp; &nbsp; 日</td>
                </tr>
                <tr >
                  <td colspan="2" style=" padding-top: 60px;">  <p> 说明：1、  丧事承办人领取骨灰和《火化证明》后，应在此证明“&nbsp;丧事承办人签名” 处签名，并将此证明交骨灰领取处业务员存档。<br /></p>
                    <p> 2、本证明丢失或损毁作废，以补发的证明为准。</p>
                    </td>
                </tr>
            </table>
        </div>`;
      //设置字体
      LODOP.SET_PRINT_STYLE("FontSize", 8);
      //调用打印控件进行测试
      // LODOP.ADD_PRINT_HTM(20, 20, 300, 25, "");
      let time = `打印时间：${dataFormate(new Date())}`;
      //打印协议
      // LODOP.SET_PRINT_PAGESIZE(1,148,210,"");//设置纸张为80mm*60mm
      // LODOP.SET_PRINT_STYLEA(0,"AngleOfPageInside",90); //设置为横向
      // LODOP.SET_PRINT_PAGESIZE(2,100,50,0);
      LODOP.ADD_PRINT_BARCODE(40, 500, 100, 100, "QRCode", recOperationcode);
      LODOP.ADD_PRINT_HTM(100, 10, 750, 500, table);
      // LODOP.ADD_PRINT_HTM(300, 10, 1000, 300, ListOfItems);
      LODOP.ADD_PRINT_HTM(20, 550, 750, 300, time);
      LODOP.PREVIEW();
    },
    //获取打印减免数据
    PrintAbatementList() {
      {
        if (!this.businessCode || this.businessCode.length === 0) {
          this.$message("请输入业务编码");
          return;
        }
        let postData = {
          businessCode: this.businessCode,
        };
        Type["loadPrintServiceChargeExemptionInfoWithBusinessCode"](
          postData
        ).then((response) => {
          const { data } = response;
          if (!data) {
            this.$message("数据读取失败");
            return;
          }
          this.PrintAbatement(data);
        });
      }
    },
    //打印减免基本殡葬服务费用申请表
    PrintAbatement(printData) {
      let this_print = this;
      let LODOP = getLodop();
      if (LODOP == null || !LODOP) {
        this_print.$.messager.alert(
          "系统提示",
          "您的浏览器不支持打印控件，请用IE重试或安装打印控件后重试"
        );
        return;
      }

      console.log(printData)

      for (let key in printData.funeralDead) {
        printData["funeralDead"][key] = printData["funeralDead"][key]
          ? printData["funeralDead"][key]
          : "　";
      }

      for (let key in printData.familyAgent) {
        printData["familyAgent"][key] = printData["familyAgent"][key]
          ? printData["familyAgent"][key]
          : "　";
      }

      let trStr = "";
      for (let i = 0; i < printData.chargeItems.length; i++) {
        trStr += `
            <br>服务项目:&ensp;${printData.chargeItems[i].itemName}&ensp;
            减免金额:&ensp;${printData.chargeItems[i].benefitCharge}`;
      }
      let dateStr=printData.currentDate;
      // let date = printData.currentDate;
      // //获取年
      // let dateYear = date.getFullYear();
      // //获取月
      // let dateMonth = date.getMonth();
      // //获取当日
      // let dateDate = date.getDate();
      let recOperationcode = printData.recCode;
      let table = `<table style="border-collapse:collapse;text-align:center">
    <tr>
    <td colspan="4" align="left">&ensp;&ensp;&ensp;&ensp;减免类型:${printData.funeralDead.exemptionType} </td>
    <td colspan="4" align="center">
    逝者编号：${printData.funeralDead.businessCode} </td>
    <tr>
    <tr>
      <td style="border: 1px solid black;width:60px;height:100px;" rowspan="2"
      >逝<br>者<br>信<br>息
      </td>
      <td style="border: 1px solid black;width:80px;height:50px;">姓名</td>
      <td style="border: 1px solid black;width:100px;height:50px" colspan="2">${printData.funeralDead.deadName}</td>
      <td style="border: 1px solid black;width:80px;height:50px">户籍地址</td>
      <td style="border: 1px solid black;width:100px;height:50px" colspan="2">
       ${printData.funeralDead.householdRegistrationPlace}</td>
    </tr>
    <tr>
      <td style="border: 1px solid black;width:80px;height:50px">年龄</td>
      <td style="border: 1px solid black;width:50px;height:50px">${printData.funeralDead.deadAge}</td>
      <td style="border: 1px solid black;width:50px;height:50px">性别</td>
      <td style="border: 1px solid black;width:80px;height:50px">${printData.funeralDead.deadGender}</td>
      <td style="border: 1px solid black;width:30px;height:50px">证件号码</td>
      <td style="border: 1px solid black;width:70px;height:50px">${printData.funeralDead.certificateNo}</td>
    </tr>
    <tr>
      <td style="border: 1px solid black;width:60px;height:220px" rowspan="2">
        减<br>免<br>项<br>目<br>及<br>金<br>额
      </td>
      <td style="border-right: 1px solid black;width:500px;height:220px" align="left" valign="top" colspan="6">
       ${trStr}
      </td>
    </tr>
    <tr>
      <td style="height: 50px" align="left" valign="bottom" colspan="2">
      减免合计: ${printData.abatementTotalCharge}</td>
      <td align="left" valign="bottom" colspan="2">大写金额: ${printData.abatementTotalChargeText}</td>
      <td style="border-right: 1px solid black;" colspan="2"></td>
    </tr>
    <tr>
      <td style="border: 1px solid black;height:190px" rowspan="3">丧<br>事<br>经<br>办<br>人</td>
      <td style="border: 1px solid black;width: 100px; height:40px">姓名</td>
      <td style="border: 1px solid black;" align="left" colspan="2">
        ${printData.familyAgent.agentName}</td>
      <td style="border: 1px solid black;width: 100px; height:40px">证件号码</td>
      <td style="border: 1px solid black;" align="left" colspan="2">
        ${printData.familyAgent.certificateNo}</td>
    </tr>
    <tr>
      <td style="border: 1px solid black;">与逝者关系</td>
      <td style="border: 1px solid black;height:40px" align="left" colspan="2">
        ${printData.familyAgent.agentRelation}</td>
      <td style="border: 1px solid black;">联系电话</td>
      <td style="border: 1px solid black;" align="left" colspan="2">
    ${printData.familyAgent.mobilePhone}</td>
    </tr>
    <tr>
      <td style="height:110px" align="left" valign="top" colspan="3"><br>签字:</td>
      <td style="border-right: 1px solid black;" align="right" valign="bottom" colspan="3">
      &ensp;&ensp;&ensp;&ensp;年&ensp;&ensp;&ensp;&ensp;月&ensp;&ensp;&ensp;&ensp;日&ensp;&ensp;<br>&ensp;
      </td>
    </tr>
    <tr>
      <td style="border: 1px solid black;height:160px" rowspan="3">殡<br>仪<br>馆<br>审<br>核<br>情<br>况</td>
      <td style="border-top: 1px solid #000000;border-right: 1px solid black;width: 100px"
          align="left" valign="top" colspan="3"><br>经办人:
      </td>
      <td style="border-right: 1px solid black;border-top: 1px solid black; width: 100px"
          align="left" valign="top" colspan="3"><br>审核意见:
      </td>
    </tr>
    <tr>
      <td style="border-right: 1px solid black;" align="left" colspan="3">
        &ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;(签字)
      </td>
      <td style="border-right: 1px solid black;" align="left" colspan="3">
        &ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;(公章)
      </td>
    </tr>
    <tr>
      <td style="border-right: 1px solid black;" align="right" valign="bottom" colspan="3">
     $(dateStr)&ensp;&ensp;
      </td>
      <td style="border-right: 1px solid black;" align="right" valign="bottom" colspan="3">
      &ensp;&ensp;&ensp;&ensp;年&ensp;&ensp;&ensp;&ensp;月&ensp;&ensp;&ensp;&ensp;日&ensp;&ensp;
      </td>
    </tr>
    <tr>
      <td style="border: 1px solid black;height:120px" colspan=>说<br>明</td>
      <td style="border: 1px solid black;" align="left" colspan="6">
        1.此表内容据实填写,弄虚作假,追回费用,并追究责。
        <br>2.未发生的免费项目不折现.不折抵。
        <br>3.此表一式三份，一份由殡仪馆存档备查，两份作为向财政部门申请资金的原始依据。
        <br>
      </td>
    </tr>
  </table>`;
      //设置字体
      LODOP.SET_PRINT_STYLE("FontSize", 8);
      //调用打印控件进行测试
      LODOP.ADD_PRINT_HTM(
        90,
        220,
        500,
        25,
        "<p style='font-size:30px;font-weight: bold;'>减免基本殡葬服务费用申请表</p>"
      );
      let time = `打印时间：${dataFormate(new Date())}`;
      //打印协议
      // LODOP.SET_PRINT_PAGESIZE(1,148,210,"");//设置纸张为80mm*60mm
      // LODOP.SET_PRINT_STYLEA(0,"AngleOfPageInside",90); //设置为横向
      // LODOP.SET_PRINT_PAGESIZE(2,100,50,0);
      LODOP.ADD_PRINT_BARCODE(40, 600, 100, 100, "QRCode", recOperationcode);
      LODOP.ADD_PRINT_HTM(130, 60, 1000, 1000, table);
      //LODOP.ADD_PRINT_HTM(20, 550, 1000, 300, time);
      LODOP.PREVIEW();
    },
    //打印未结算清单明细
    printChargeDetailWithId(printData) {
      let this_print = this;
      let LODOP = getLodop();
      if (LODOP == null || !LODOP) {
        this_print.$.messager.alert(
          "系统提示",
          "您的浏览器不支持打印控件，请用IE重试或安装打印控件后重试"
        );
        return;
      }
      for (let key in printData) {
        printData[key] = printData[key] ? printData[key] : "　";
      }
      //当前业务时间
      let businessTime = dataFormate(new Date());

      //业务编码
      let firstParty = "临沂市第二殡仪馆";
      //标题
      let title = "<b>" + firstParty + "费用明细单</b>";
      //业务编号
      let businessCode = printData.businessCode;
      //逝者姓名
      let deadName = "" + printData.deadName;
      //付款方式
      let settleType = printData.settleType == null ? "" : printData.settleType;
      //收费日期
      let settleTime = printData.chargeDate;
      let chargeItems = printData.chargeItems;
      let tableHead =
        "<table><tr><td>逝者姓名：</td><td>" +
        deadName +
        "</td><td>付款方式" +
        settleType +
        "</td><td>收费日期</td><td>" +
        settleTime +
        "</td></tr>";
      let chargeItemStr = "<tr>";
      if (chargeItems && chargeItems.length > 0) {
        let item = null;
        for (let k = 0; k < chargeItems.length; k++) {
          item = chargeItems[k];
          chargeItemStr +=
            "<td>" + item.itemName + "</td><td>" + item.itemCharge + "</td>";
          if (k != 0 && k % 3 == 0 && k != chargeItems.length - 1) {
            chargeItemStr += "</tr><tr>";
          }
        }
        chargeItemStr += "</tr>";
      }
      //制单日期
      let printTime = "制单日期：" + printData.printDate;
      //应收
      let yingShou = "应收：" + printData.itemTotalCharge;
      //费用减免
      let chargeJianMian =
        "费用减免：" + printData.discountTotalCharge == null
          ? 0
          : printData.discountTotalCharge;
      //实收
      let activeCharge = "实收：" + printData.realityTotalCharge;
      //大写
      let txtDaXie = "大写：" + printData.realityTotalChargeText;
      //制单人
      let markMan = printData.userFullName;
      let tableBottom =
        "<tr><td colspan='7'>" +
        yingShou +
        chargeJianMian +
        activeCharge +
        txtDaXie +
        "</td></tr></table>";
      let table = tableHead + chargeItemStr + tableBottom;
      //生前住址
      //纸张
      LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
      //设置字体
      LODOP.SET_PRINT_STYLE("FontSize", 11);
      //调用打印控件进行测试
      LODOP.ADD_PRINT_HTM(50, 280, 300, 25, title);
      LODOP.ADD_PRINT_TEXT(90, 450, 300, 25, "业务编号：" + businessCode);
      //打印明细
      LODOP.ADD_PRINT_HTM(120, 50, 650, 125, table);
      // //制单日期
      // LODOP.ADD_PRINT_TEXT(300, 50, 300, 25, printTime);
      // //制单人
      // LODOP.ADD_PRINT_TEXT(300, 400, 500, 25, markMan);
      //打印预览
      LODOP.PREVIEW();
      //直接打印
      //LODOP.PRINT();
      //LODOP.PRINT_DESIGN();
    },
    //打印骨灰二维码
    printBoneAsh(printData) {
      //打印服务协议单
      let this_print = this;
      let LODOP = getLodop();
      if (LODOP == null || !LODOP) {
        this_print.$.messager.alert(
          "系统提示",
          "您的浏览器不支持打印控件，请用IE重试或安装打印控件后重试"
        );
        return;
      }

      //业务编码
      let businessCode = printData.funeralDead.businessCode;
      //逝者姓名
      let deadName = printData.funeralDead.deadName;
      //逝者死亡原因
      let deathCause = printData.funeralDead.deathCause;
      //逝者年龄
      let deadAge = printData.funeralDead.deadAge;
      //殡仪馆
      let firstParty = "XX殡仪馆";
      //逝者家属
      let memberName = printData.familyMember.memberName;
      //家属联系手机
      let mobilePhone = printData.mobilePhone;

      //逝者性别
      let deadGender = printData.funeralDead.deadGender;
      //纸张
      //LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
      //设置字体
      LODOP.SET_PRINT_STYLE("FontSize", 11);
      //调用打印控件进行测试
      LODOP.ADD_PRINT_BARCODE(39, 50, 100, 100, "QRCode", businessCode);
      LODOP.ADD_PRINT_TEXT(39, 150, 350, 25, businessCode);
      LODOP.ADD_PRINT_HTM(60, 150, 300, 25, "逝者: " + deadName);
      LODOP.ADD_PRINT_TEXT(
        90,
        150,
        350,
        25,
        "性别：" + deadGender + "年龄:" + deadAge
      );
      LODOP.ADD_PRINT_HTM(120, 150, 300, 25, deathCause);
      LODOP.ADD_PRINT_TEXT(150, 150, 300, 25, "家属姓名：" + memberName);
      //打印边框
      //LODOP.ADD_PRINT_RECT(60,55,500,300,0,1);
      // LODOP.ADD_PRINT_TABLE(115,50,300,300,tableStr);
      //直接打印
      //打印预览
      LODOP.PREVIEW();
      //LODOP.PRINT();
      //LODOP.PRINT_DESIGN();
    }, //载入已结算费用清单
    loadChargeSettleDetailWithId() {
      let this_print = this;
      //选中历史
      let chargeItems = this.multipleSelectionHistory;
      let item = null;
      let chargeArray = [];
      if (chargeItems && chargeItems.length > 0) {
        for (let i = 0; i < chargeItems.length; i++) {
          item = chargeItems[i];
          chargeArray.push({
            id: item.id,
            version: item.version,
          });
        }
      }
      let postData = {
        businessCode: this_print.businessCode,
        ids: chargeArray,
      };
      Type["loadPrintChargeSettleDetailsWithId"](postData)
        .then((response) => {
          //接收返回数据
          let result = response.data;
          //调用打印接口
          this_print.printChargeSettleDetailWithId(result);
        })
        .catch((error) => {
          this_print.$message(error);
        });
    }, //打印结算清单明细
    printChargeSettleDetailWithId(printData) {
      let this_print = this;
      let LODOP = getLodop();
      if (LODOP == null || !LODOP) {
        this_print.$.messager.alert(
          "系统提示",
          "您的浏览器不支持打印控件，请用IE重试或安装打印控件后重试"
        );
        return;
      }
       for (let key in printData) {
        printData[key] = printData[key] ? printData[key] : "　";
      }
      //二维码
      let recCode = printData.businessCode;
      //减免类型
      let jianMianType = "减免类型：" + "减免类型";
      //业务编码
      let businessCode = printData.businessCode;
      //付款方式
      let selltedType = printData.payType;
      //收费日期
      let businessTime = printData.chargeDate;
      //业务编码
      let title = "临沂市第二殡仪馆 费用明细单";
      //逝者姓名
      let deadName = printData.deadName.replace(/(\s*$)/g, "");;
      let chargeItems = printData.chargeItems;
      let chargeItemStr =
        "<tr style='border-style: none;height:25px;'>" +
        "<td style='width: 115px'>服务项目</td><td style='60px'>应收</td>" +
        "<td style='width: 115px'>服务项目</td><td style='60px'>应收</td>" +
        "<td style='width: 115px'>服务项目</td><td style='60px'>应收</td>" +
        "<td style='width: 115px'>服务项目</td><td style='60px'>应收</td>" +
        "<td style='width: 115px'>服务项目</td><td style='60px'>应收</td></tr><tr style='border-style: none;height:25px;'>";
      if (chargeItems && chargeItems.length > 0) {
        let item = null;
        for (let k = 0; k < chargeItems.length; k++) {
          item = chargeItems[k];
          chargeItemStr +=
            "<td>" + item.itemName + "</td><td>" + item.itemCharge + "</td>";
          if (k != 0 && (k+1) % 5 == 0&&k!=chargeItems.length-1) {
            chargeItemStr += "</tr><tr style='height:35px;'>";
          }
          if (k==chargeItems.length-1&&(k+1)%5!=0){
            for(let kk=0;kk<(5-(k+1)%5);kk++){
              chargeItemStr+="<td>&nbsp;</td><td>&nbsp;</td>";

            }
          }
        }
        chargeItemStr += "</tr>";
      }
      let discountChargeItems = printData.discountChargeItems;
      let jianMainStr = "<tr style='height:25px;'>";
      if (discountChargeItems && discountChargeItems.length > 0) {
        let jianMainItem = null;
        for (let j = 0; j < discountChargeItems.length; j++) {
          jianMainItem = discountChargeItems[j];
          jianMainStr += jianMainItem.itemName + jianMainItem.itemPrice;
        }
      }
      jianMainStr += "</tr>";
      //制单日期
      let printTime = "制单日期：" + printData.printDate;
      //应收
      let yingShou = "应收：" + printData.itemTotalCharge;
      let huiMin = "　优惠：" + printData.discountTotalCharge + "　减免：" + printData.benefitTotalCharge; //"优惠减免："+ printData.benefitTotalCharge;

      //费用减免
      let chargeJianMian = "0";
      if (printData.discountTotalCharge != null && printData.discountTotalCharge.trim().length != 0) {
        chargeJianMian = printData.discountTotalCharge;
      }
      chargeJianMian = "费用减免：" + chargeJianMian;
      //实收
      let activeCharge = "实收：" + printData.realityTotalCharge;
      //大写
      let realityTotalChargeText = "大写：" + printData.realityTotalChargeText;
      //制单人
      let markMan = "制单人：" + printData.userFullName;
      let beforeDeathAddress = printData.beforeDeathAddress;

      let dataTable="<table class='tbl' align='center' cellpadding='0' cellspacing='0' width='720px' border='1' style='text-align: center ;border-collapse: collapse;font-size: 10pt;'>"+
        chargeItemStr+
        "<tr style='height:25px;'><td colspan='10'>" + yingShou + "&nbsp;&nbsp;" + huiMin + "&nbsp;&nbsp;" + activeCharge +"&nbsp;&nbsp;<br/>"+ realityTotalChargeText + "</td></tr>"+
        "</table>";
      dataTable+="<table align='center' width='720px'><tr><td width='450px'>"+printTime+"</td><td>"+markMan+"</td></tr></table>";

      let theTitle="<p style='font-size:20px;font-weight: bold; width: 700px;height: 80px;text-align: center'>" + title + "</p>"
      //纸张
      //LODOP.PRINT_INITA(10, "0%", "100%", "100%", "打印收费明细");
      LODOP.SET_PRINT_PAGESIZE(1, 0,0, "A4");
      //设置字体
      LODOP.SET_PRINT_STYLE("FontSize", 11);
      //调用打印控件进行测试
      LODOP.ADD_PRINT_BARCODE("4mm", "160mm", "28mm", "28mm", "QRCode", recCode);
    //  LODOP.ADD_PRINT_BARCODE(39, 500, 50, 50, "QRCode", recCode);
      LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 2);
            LODOP.SET_PRINT_STYLEA(0, "DataCharset", "UTF-8");
      LODOP.ADD_PRINT_HTM( 10,20,"100%",600, theTitle+dataTable);
      //LODOP.ADD_PRINT_TEXT(90, 50, 350, 25, jianMianType);
      LODOP.ADD_PRINT_TEXT(50, "15mm", 500, 25, "业务编号：" + businessCode);
      LODOP.ADD_PRINT_TEXT(70, "15mm", 500, 25, "逝者姓名：" + deadName+",  付款方式：" + selltedType + ",  收费日期：" + businessTime);
      // //打印明细
      // LODOP.ADD_PRINT_HTM(120, 50, 650, 300, dataTable);

      LODOP.SET_SHOW_MODE("SHOW_SCALEBAR", false);
      // LODOP.ADD_PRINT_HTM(260, 50, 350, 25, printTime);
      // LODOP.ADD_PRINT_HTM(260, 400, 650, 25, markMan);
      //打印预览
      LODOP.PREVIEW();
      //直接打印
      //LODOP.PRINT();
      //LODOP.PRINT_DESIGN();
    },
    printItems() {
      this.$message("打印明细");
      if (this.multipleSelection.length == 0) {
        this.$message("请选择服务项目");
        return;
      }
    }, //打印发票
    printInvoice() {
      let printFlag = this.checkPrintInvoice();
      if (!printFlag) {
        this.$message(
          "请选择未打印过发票或未退费的结算记录打印，打印过的请进发票管理重打！"
        );
      } else {
        this.PrintInvoiceFlag = true;
      }
    }, //检查打印发票的选择项
    checkPrintInvoice() {
      let flag = true;
      //采用后台验证,后面接口完成后改成后台验证方式
      let selectData = this.multipleSelectionHistory;
      let totalCharge = 0;
      if (selectData && selectData.length > 0) {
        let item = null;
        for (let i = 0; i < selectData.length; i++) {
          item = selectData[i];
          let settleCharge = new Number(item.settleCharge);
          totalCharge += settleCharge;
          //item.asRefund==1只是记录不能退费，不能记录不能打印发票
          if (item.invoiceNo || item.invoiceCode) {
            flag = false;
            break;
          }
        }
      }
      if (totalCharge <= 0) {
        flag = false;
        return flag;
      }
      return flag;
    },
    //发票管理
    InvoiceManager() {
      this.InvoiceDialogFlag = true;
    },
    //退费
    Refund(index) {
      let ids = [];
      this.multipleSelectionHistory.forEach((n) => {
        if (n.id) {
          ids.push(n.id);
        }
      });
      let postData = {
        businessCode: this.businessCode,
        ids: ids,
      };
      Type["savechargesettletorefund"](postData)
        .then((response) => {
          this.$message(response.msg);
          this.chargeData = data;
        })
        .catch((error) => {
          this.$message(error);
        });
    },
    //直接付款
    NowPay() {
      if (this.multipleSelection.length == 0) {
        this.$message("请选择服务项目");
        return;
      }
      this.NowPayFlag = true;
    }, //表头样式
    tableHeadClass({ row, rowIndex }) {
      // console.log(rowIndex) //表头行标号为0
      return {
        color: "#333",
        fontSize: "14px",
        fontWeight: 900,
        background: "#eee",
      };
    },
  },
  computed: {
    Charge() {
      let charge = {
        total: 0.0,
        Settled: 0.0,
        discountCharge: 0.0,
        benefitCharge: 0.0,
        realityCharge: 0.0,
        unSettled: 0.0,
        unDiscountCharge: 0.0,
        unBenefitCharge: 0.0,
        unrealityCharge: 0.0,
      };
      this.chargeData.chargeItems.forEach((n) => {
        if (n.asSettled == 1) {
          //已结算
          if (n.itemCharge) {
            charge.Settled += Number(n.itemCharge);
          }
          if (n.discountCharge) {
            charge.discountCharge += Number(n.discountCharge);
          }
          if (n.benefitCharge) {
            charge.benefitCharge += Number(n.benefitCharge);
          }
        } else if (n.asSettled == 0) {
          //未结算
          if (n.itemCharge) {
            charge.unSettled += Number(n.itemCharge);
          }
          if (n.discountCharge) {
            charge.unDiscountCharge += Number(n.discountCharge);
          }
          if (n.benefitCharge) {
            charge.unBenefitCharge += Number(n.benefitCharge);
          }
        }
      });
      /*总费用合计*/
      charge.total = Number(charge.unSettled) + Number(charge.Settled);
      /*未结算*/
      charge.unrealityCharge =
        Number(charge.unSettled) -
        Number(charge.unDiscountCharge) -
        Number(charge.unBenefitCharge);
      /*已结算*/
      charge.realityCharge =
        Number(charge.Settled) -
        Number(charge.discountCharge) -
        Number(charge.benefitCharge);
      for (let i in charge) {
        charge[i] = toFixed(charge[i], 2);
      }
      return charge;
    },
  },
  watch: {
    NowPayFlag() {
      if (this.NowPayFlag == false) {
        this.ReadData();
      }
    },
    PrintInvoiceFlag() {
      if (this.PrintInvoiceFlag == false) {
        this.ReadData();
      }
    }  ,
  'RefundDialogFlag'() {
    if (this.RefundDialogFlag == false) {
      this.ReadData()
    }
  },
  }
}
</script>
<style>
.TotalMoney .el-dialog__header {
  background-color: cornflowerblue !important;
  color: #fff;
}

.TotalMoney .PageContent .el-select .el-input,
.TotalMoney .PageContent .el-select {
  width: 10vw;
  min-width: 120px;
}
</style>
<style scoped>
.el-form-item {
  margin-bottom: 5px !important;
}

.border1 {
  border: 1px solid #e2dada;
  padding: 10px;
}

.marginright50 {
  margin-right: 50px;
}

.edit-cell {
  padding: 3px;
}

.totalw {
  display: inline-block;
  width: 80px;
  font-weight: 600;
}

</style>
